/*
 * @Author: your name
 * @Date: 2021-09-03 09:22:07
 * @LastEditTime: 2021-09-03 10:38:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day10\工厂模式.js
 */

function newPerson(name, age, gender) {
    var p = new Object();
    p.name = name;
    p.age = age;
    p.gender = gender;
    p.sayName = function() {
        console.log(this.name);
    };
    return p;
}
var p1 = newPerson("zs", 12, "男");
var p2 = newPerson("lisi", 10, "男");
var p3 = newPerson("ww", 16, "女");
p1.sayName(); //zs
p2.sayName(); //lisi
p3.sayName(); //ww
console.log(p1); //{ name: 'zs', age: 12, gender: '男', sayName: [Function (anonymous)] }
console.log(p2); //{ name: 'lisi', age: 10, gender: '男', sayName: [Function (anonymous)] }
console.log(p3); //{ name: 'ww', age: 16, gender: '女', sayName: [Function (anonymous)] }  

function newDog(name, age, gender) {
    var d = new Object();
    d.name = name;
    d.age = age;
    d.gender = gender;
    d.sayName = function() {
        console.log("汪汪的名字是:" + this.name);
    }
    return d;
}
var d1 = newDog("旺财", 3, "男");
console.log(d1); //{ name: '旺财', age: 3, gender: '男', sayName: [Function (anonymous)] } 
d1.sayName(); //汪汪的名字是:旺财

console.log(typeof p1); //object
console.log(typeof d1); //object